home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Everything / Radios.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  11.2 KB  |  490 lines  |  [TEXT/CWIE]

  1. { Radios.p }
  2. { Created 10/30/98 1:06 PM by AppMaker }
  3.  
  4. Unit Radios;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     Resources,
  16.     TextEdit,
  17.     ToolUtils,
  18.  
  19.     DDocData,
  20.     EverythingEngine,
  21.     EverythingDoc,
  22.     AMWindow;
  23.  
  24. type
  25.     Radios        = object (AMWindow)
  26.  
  27.     {data members}
  28.         mData:            DDocData;
  29.         mRadioGroupGroupHandle:        ControlHandle;
  30.         mStandard3Handle:        ControlHandle;
  31.         mGroupBoxHandle:        ControlHandle;
  32.         mGroupGroupHandle:        ControlHandle;
  33.         mGroupRadio1Handle:    ControlHandle;    // Fred
  34.         mGroupRadio2Handle:    ControlHandle;    // George
  35.         mGroupRadio3Handle:    ControlHandle;    // Harry
  36.         mGraphic3BoxHandle:        ControlHandle;
  37.         mGraphic3GroupHandle:        ControlHandle;
  38.         mStopHandle:        ControlHandle;
  39.         mGoHandle:        ControlHandle;
  40.         mBevel3BoxHandle:        ControlHandle;
  41.         mBevel3GroupHandle:        ControlHandle;
  42.         mRadioButtonHandle:        ControlHandle;
  43.         mRadioButton2Handle:        ControlHandle;
  44.         mTextBoxHandle:        ControlHandle;
  45.         mTextGroupHandle:        ControlHandle;
  46.         mNameHandle:        ControlHandle;
  47.         mKindHandle:        ControlHandle;
  48.         mSizeHandle:        ControlHandle;
  49.  
  50.     {methods}
  51.         Procedure Initialize; Override;
  52.  
  53.         Procedure Open        (inDoc:        EverythingDoc;
  54.                              inData:    DDocData);
  55.         Procedure Close; Override;
  56.  
  57.         Procedure Control    (whichControl:    ControlHandle;
  58.                               whichPart:        integer;
  59.                              where:            Point); Override;
  60.         Procedure MouseIn    (where:            Point;
  61.                              modifiers:        integer); Override;
  62.         Procedure TypeIn    (charCode:        SInt16); Override;
  63.         Procedure ExitCurField; Override;
  64.         Procedure DataChanged    (inDataID:    longint); Override;
  65.         Procedure Resize; Override;
  66.         Procedure Scroll    (newValue:        integer;
  67.                              oldValue:        integer); Override;
  68.  
  69.         Function  GetEngine: EverythingEngine;
  70.  
  71. {$ifc false}
  72.         Procedure UpdateMenus; Override;
  73. {$endif}
  74.         Function  DoCommand        (inCommand:    longint): Boolean; Override;
  75.  
  76.         Procedure DoUndo;
  77.         Procedure DoCut;
  78.         Procedure DoCopy;
  79.         Procedure DoPaste;
  80.         Procedure DoClear;
  81.         Procedure DoSelectAll;
  82.         Procedure DoShowClipboard;
  83.  
  84.     end;
  85.  
  86. {----------}
  87. Procedure CreateRadios    (inDoc:        EverythingDoc;
  88.                              inData:    DDocData);
  89.  
  90. {----------}
  91. Implementation
  92.  
  93. Uses
  94.     Globals,
  95.     ResourceDefs,
  96.     DoScrap,
  97.     Scrolling,
  98.     ControlUtils,
  99.     Miscellany;
  100.  
  101. const
  102.     kRadioGroupGroup        = 1;
  103.     kStandard3Radio        = 1;
  104. kGroupBox        = 2;
  105.     kGroupGroup        = 3;
  106.         kGroupRadio1        = 3;
  107.         kGroupRadio2        = 4;
  108.         kGroupRadio3        = 5;
  109. kGraphic3Box        = 6;
  110.     kGraphic3Group        = 7;
  111.     kStopRadio        = 7;
  112.     kGoRadio        = 8;
  113. kBevel3Box        = 9;
  114.     kBevel3Group        = 10;
  115.     kRadioButtonRadio        = 10;
  116.     kRadioButton2Radio        = 11;
  117. kTextBox        = 12;
  118.     kTextGroup        = 13;
  119.     kNameRadio        = 13;
  120.     kKindRadio        = 14;
  121.     kSizeRadio        = 15;
  122.  
  123. {----------}
  124. Procedure CreateRadios (
  125.     inDoc:        EverythingDoc;
  126.     inData:        DDocData);
  127. var
  128.     winObj:        Radios;
  129. begin
  130.     winObj := nil;
  131.     New (winObj);
  132.  
  133.     if winObj <> nil then begin
  134.         winObj.Initialize;
  135.         winObj.Open (inDoc, inData);
  136.     end;
  137. end;
  138.  
  139. {----------}
  140. Procedure Radios.Initialize;
  141. begin
  142.     Inherited Initialize;
  143. end;
  144.  
  145. {----------}
  146. Function  Radios.GetEngine: EverythingEngine;
  147. begin
  148.     GetEngine := EverythingEngine (mDoc.mEngine);
  149. end;
  150.  
  151. {----------}
  152. Procedure Radios.Open (
  153.     inDoc:        EverythingDoc;
  154.     inData:        DDocData);
  155. var
  156.     window:        WindowPtr;
  157.     wftb:        Handle;
  158.     errCode:    OSErr;
  159. begin
  160.     mDoc := inDoc;
  161.     mData := inData;
  162.     mData.AddResponder (self);
  163.  
  164.     window := GetNewCWindow (WIND_Radios, nil, WindowPtr (-1));
  165.     if inDoc.mEngine.GetFilename <> '' then begin
  166.         SetWTitle (window, inDoc.mEngine.GetFilename);
  167.     end;
  168.     mWindow := window;
  169.     EverythingDoc (mDoc).mRadiosPtr := window;
  170.  
  171.     WindowPeek (window)^.windowKind := kAMWindowFlag;
  172.     SetWRefCon (window, ord4 (self));
  173.     SetPort (window);
  174.     SetInfo (window);
  175.  
  176.     wftb := GetResource ('Wftb', WIND_Radios);
  177.  
  178.     errCode := CreateRootControl (window, mRootControl);
  179.  
  180.     vScroll := nil;
  181.     hScroll := nil;
  182.  
  183.  
  184.     mRadioGroupGroupHandle := GetNewControl (CNTL_RadioGroupGroup, window);
  185.     mStandard3Handle := GetNewControl (CNTL_Standard3, window);
  186.     errCode := EmbedControl (mStandard3Handle, mRadioGroupGroupHandle);
  187.     SetWindowItemFont (mStandard3Handle, wftb, 2);
  188.  
  189.     mGroupBoxHandle := GetNewControl (CNTL_GroupBox, window);
  190.     SetWindowItemFont (mGroupBoxHandle, wftb, 3);
  191.     mGroupGroupHandle := GetNewControl (CNTL_GroupGroup, window);
  192.     errCode := EmbedControl (mGroupGroupHandle, mGroupBoxHandle);
  193.     mGroupRadio1Handle := GetNewControl (CNTL_GroupRadio1, window);
  194.     SetWindowItemFont (mGroupRadio1Handle, wftb, 5);
  195.     errCode := EmbedControl (mGroupRadio1Handle, mGroupGroupHandle);
  196.     mGroupRadio2Handle := GetNewControl (CNTL_GroupRadio2, window);
  197.     SetWindowItemFont (mGroupRadio2Handle, wftb, 6);
  198.     errCode := EmbedControl (mGroupRadio2Handle, mGroupGroupHandle);
  199.     mGroupRadio3Handle := GetNewControl (CNTL_GroupRadio3, window);
  200.     SetWindowItemFont (mGroupRadio3Handle, wftb, 7);
  201.     errCode := EmbedControl (mGroupRadio3Handle, mGroupGroupHandle);
  202.  
  203.     mGraphic3BoxHandle := GetNewControl (CNTL_Graphic3Box, window);
  204.     SetWindowItemFont (mGraphic3BoxHandle, wftb, 8);
  205.     mGraphic3GroupHandle := GetNewControl (CNTL_Graphic3Group, window);
  206.     errCode := EmbedControl (mGraphic3GroupHandle, mGraphic3BoxHandle);
  207.     mStopHandle := GetNewControl (CNTL_Stop, window);
  208.     errCode := EmbedControl (mStopHandle, mGraphic3GroupHandle);
  209.     SetWindowItemFont (mStopHandle, wftb, 10);
  210.     mGoHandle := GetNewControl (CNTL_Go, window);
  211.     errCode := EmbedControl (mGoHandle, mGraphic3GroupHandle);
  212.     SetWindowItemFont (mGoHandle, wftb, 11);
  213.  
  214.     mBevel3BoxHandle := GetNewControl (CNTL_Bevel3Box, window);
  215.     SetWindowItemFont (mBevel3BoxHandle, wftb, 12);
  216.     mBevel3GroupHandle := GetNewControl (CNTL_Bevel3Group, window);
  217.     errCode := EmbedControl (mBevel3GroupHandle, mBevel3BoxHandle);
  218.     mRadioButtonHandle := GetNewControl (CNTL_RadioButton, window);
  219.     errCode := EmbedControl (mRadioButtonHandle, mBevel3GroupHandle);
  220.     SetWindowItemFont (mRadioButtonHandle, wftb, 14);
  221.     errCode := SetBevelButtonGraphicAlignment (mRadioButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
  222.     mRadioButton2Handle := GetNewControl (CNTL_RadioButton2, window);
  223.     errCode := EmbedControl (mRadioButton2Handle, mBevel3GroupHandle);
  224.     SetWindowItemFont (mRadioButton2Handle, wftb, 15);
  225.     errCode := SetBevelButtonGraphicAlignment (mRadioButton2Handle, kControlBevelButtonAlignCenter, 0, 0);
  226.  
  227.     mTextBoxHandle := GetNewControl (CNTL_TextBox, window);
  228.     SetWindowItemFont (mTextBoxHandle, wftb, 16);
  229.     mTextGroupHandle := GetNewControl (CNTL_TextGroup, window);
  230.     errCode := EmbedControl (mTextGroupHandle, mTextBoxHandle);
  231.     mNameHandle := GetNewControl (CNTL_Name, window);
  232.     errCode := EmbedControl (mNameHandle, mTextGroupHandle);
  233.     SetWindowItemFont (mNameHandle, wftb, 18);
  234.     mKindHandle := GetNewControl (CNTL_Kind, window);
  235.     errCode := EmbedControl (mKindHandle, mTextGroupHandle);
  236.     SetWindowItemFont (mKindHandle, wftb, 19);
  237.     mSizeHandle := GetNewControl (CNTL_Size, window);
  238.     errCode := EmbedControl (mSizeHandle, mTextGroupHandle);
  239.     SetWindowItemFont (mSizeHandle, wftb, 20);
  240.  
  241.     errCode := AdvanceKeyboardFocus (window);
  242.  
  243.     ShowWindow (window);
  244. end;
  245.  
  246. {----------}
  247. Procedure Radios.Close;
  248. begin
  249.     mData.RemoveResponder (self);
  250.  
  251.     EverythingDoc (mDoc).mRadiosPtr := nil;
  252.     SetInfo (nil);
  253.     HideWindow (mWindow);
  254.     DisposeWindow (mWindow);
  255.  
  256.     Dispose (self);
  257. end;
  258.  
  259. {----------}
  260. Procedure Radios.Control (
  261.     whichControl:    ControlHandle;
  262.     whichPart:        integer;
  263.     where:            Point);
  264. var
  265.     bounds:            Rect;
  266.     newValue:        integer;
  267.     partcode:        SInt16;
  268. begin
  269.     ExitCurField ();
  270.  
  271.     if whichControl = mRadioGroupGroupHandle then begin
  272.         if TrackClick (whichControl, where) then begin
  273.             mData.SetRadioGroup (GetControlValue (mRadioGroupGroupHandle));
  274.         end;
  275.     end;
  276.     if whichControl = mGroupGroupHandle then begin
  277.         if TrackClick (whichControl, where) then begin
  278.             mData.SetGroup (GetControlValue (mGroupGroupHandle));
  279.         end;
  280.     end;
  281.     if whichControl = mGraphic3GroupHandle then begin
  282.         if TrackClick (whichControl, where) then begin
  283.             mData.SetGraphic (GetControlValue (mGraphic3GroupHandle));
  284.         end;
  285.     end;
  286.     if whichControl = mBevel3GroupHandle then begin
  287.         if TrackClick (whichControl, where) then begin
  288.             mData.SetBevel (GetControlValue (mBevel3GroupHandle));
  289.         end;
  290.     end;
  291.     if whichControl = mTextGroupHandle then begin
  292.         if TrackClick (whichControl, where) then begin
  293.             mData.SetText (GetControlValue (mTextGroupHandle));
  294.         end;
  295.     end;
  296. end;
  297.  
  298. {----------}
  299. Procedure Radios.DataChanged (
  300.     inDataID:        longint);
  301. begin
  302.     if inDataID = idRadioGroup then begin
  303.         SetControlValue (mRadioGroupGroupHandle, mData.GetRadioGroup);
  304.     end;
  305.     if inDataID = idGroup then begin
  306.         SetControlValue (mGroupGroupHandle, mData.GetGroup);
  307.     end;
  308.     if inDataID = idGraphic then begin
  309.         SetControlValue (mGraphic3GroupHandle, mData.GetGraphic);
  310.     end;
  311.     if inDataID = idBevel then begin
  312.         SetControlValue (mBevel3GroupHandle, mData.GetBevel);
  313.     end;
  314.     if inDataID = idText then begin
  315.         SetControlValue (mTextGroupHandle, mData.GetText);
  316.     end;
  317. End;
  318.  
  319. {----------}
  320. Procedure Radios.MouseIn (
  321.     where:            Point;
  322.     modifiers:        integer);
  323. var
  324.     bounds:            Rect;
  325. begin
  326. end;
  327.  
  328. {----------}
  329. Procedure Radios.ExitCurField;
  330. var
  331.     errCode:    OSErr;
  332.     focus:        ControlHandle;
  333. begin
  334.     errCode := GetKeyboardFocus (mWindow, focus);
  335.  
  336.     if focus = nil then begin
  337.         { nothing to exit }
  338.  
  339.     end;
  340.     inherited ExitCurField;
  341. end;
  342.  
  343. {----------}
  344. Procedure Radios.TypeIn (
  345.     charCode:    SInt16);
  346. var
  347.     ch:            char;
  348.     errCode:    OSErr;
  349.     focus:        ControlHandle;
  350.     keyCode:    SInt16;
  351.     partcode:    SInt16;
  352. begin
  353.     errCode := GetKeyboardFocus (mWindow, focus);
  354.  
  355.     ch := chr (charCode);
  356.     if (ch = charEnter)
  357.     |  (ch = charReturn) then begin
  358.         ExitCurField;
  359.     end else if ch = charEsc then begin
  360.     end else if ch = charTab then begin
  361.         DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
  362.     end else if focus <> nil then begin
  363.         keyCode := BAnd (curEvent.message, keyCodeMask);
  364.         partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
  365.         mDoc.mEngine.SetDirty;
  366.     end else begin
  367.         SysBeep (1);
  368.     end;
  369. end;
  370.  
  371. {----------}
  372. Procedure Radios.Resize;
  373. begin
  374.     { application-specific code to resize items in window }
  375. end;
  376.  
  377. {----------}
  378. Procedure Radios.Scroll (
  379.     newValue:    integer;
  380.     oldValue:    integer);
  381. begin
  382.     { application-specific code to scroll window }
  383.     if gWhichScroll = vScroll then begin
  384.     end else begin    { horizontal }
  385.     end;
  386. end;
  387.  
  388. {----------}
  389. Procedure Radios.DoUndo;
  390. begin
  391. end; {DoUndo}
  392.  
  393. {----------}
  394. Procedure Radios.DoCut;
  395. var
  396.     curTE:        TEHandle;
  397. begin
  398.     curTE := GetCurTE ();
  399.  
  400.     if curTE <> nil then begin
  401.         TECut (curTE);
  402.         mDoc.mEngine.SetDirty;
  403.         scrapDirty := true;
  404.     end;
  405. end; {DoCut}
  406.  
  407. {----------}
  408. Procedure Radios.DoCopy;
  409. var
  410.     curTE:        TEHandle;
  411. begin
  412.     curTE := GetCurTE ();
  413.  
  414.     if curTE <> nil then begin
  415.         TECopy (curTE);
  416.         scrapDirty := true;
  417.     end;
  418. end; {DoCopy}
  419.  
  420. {----------}
  421. Procedure Radios.DoPaste;
  422. var
  423.     curTE:        TEHandle;
  424. begin
  425.     curTE := GetCurTE ();
  426.  
  427.     if curTE <> nil then begin
  428.         TEPaste (curTE);
  429.         mDoc.mEngine.SetDirty;
  430.     end;
  431. end; {DoPaste}
  432.  
  433. {----------}
  434. Procedure Radios.DoClear;
  435. var
  436.     curTE:        TEHandle;
  437. begin
  438.     curTE := GetCurTE ();
  439.  
  440.     if curTE <> nil then begin
  441.         TEDelete (curTE);
  442.         mDoc.mEngine.SetDirty;
  443.     end;
  444. end; {DoClear}
  445.  
  446. {----------}
  447. Procedure Radios.DoSelectAll;
  448. var
  449.     curTE:        TEHandle;
  450. begin
  451.     curTE := GetCurTE ();
  452.  
  453.     if curTE <> nil then begin
  454.         TESetSelect (0, 32767, curTE);
  455.     end;
  456. end; {DoSelectAll}
  457.  
  458. {----------}
  459. Procedure Radios.DoShowClipboard;
  460. begin
  461. end; {DoShowClipboard}
  462.  
  463. {----------}
  464. Function Radios.DoCommand (
  465.     inCommand:        longint): Boolean;
  466. begin
  467.     DoCommand := true;
  468.     case inCommand of
  469.         cmdUndo:
  470.                 DoUndo;
  471.         cmdCut:
  472.                 DoCut;
  473.         cmdCopy:
  474.                 DoCopy;
  475.         cmdPaste:
  476.                 DoPaste;
  477.         cmdClear:
  478.                 DoClear;
  479.         cmdSelectAll:
  480.                 DoSelectAll;
  481.         cmdShowClipboard:
  482.                 DoShowClipboard;
  483.  
  484.         otherwise
  485.                 DoCommand := false;
  486.     end; {case}
  487. end;
  488.  
  489. end.
  490.